package cn.jinjimi.app.modules.drp;

import android.text.TextUtils;

import com.google.gson.annotations.SerializedName;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.app.entity.AppConfig.AppAlert;
import cn.jinjimi.app.entity.AppConfig.AppModule;
import cn.jinjimi.app.managers.ConfigManager;
import cn.jinjimi.app.modules.IModule;

import java.util.List;

/**
 * Created by zhenhua on 16/5/20.
 */
public class Drp implements IModule<Drp.Config> {

    private static volatile Drp mInstance = null;

    private Config mConfig;

    public static Drp getInstance() {
        if (mInstance == null) {
            synchronized (Drp.class) {
                if (mInstance == null) {
                    mInstance = new Drp();
                }
            }
        }
        return mInstance;
    }

    /**
     * 获取当前模块的配置
     *
     * @return
     */
    @Override
    public Config getConfig() {
        if (mConfig == null) {
            String config = ConfigManager.getInstance().getConfig(AppModule.ModuleDrp);
            mConfig = GsonUtils.fromJson(config, Config.class);
        }
        return mConfig;
    }

    public Config createConfig() {
        String data = ConfigManager.getInstance().getConfig(AppModule.ModuleDrp);
        mConfig = GsonUtils.fromJson(data, Config.class);
        return mConfig;
    }

    public static class Config {
        /* 赚多保，去推广 */
        @SerializedName("entrance_url")
        public String entrance;

        /* 我的推广费地址 */
        @SerializedName("myprofit_url")
        public String profit;

        /* 可提现链接 */
        @SerializedName("transfer_url")
        public String transfer;

        /* 去投保链接 */
        @SerializedName("insure_url")
        public String insure;

        /* 累计成交链接地址 */
        @SerializedName("orders_url")
        public String orders;

        /* 体检卡产品地址 */
        @SerializedName("examined_products_url")
        public String examinedPro;

        /* 累计推广费地址 */
        @SerializedName("accumulated_profit_url")
        public String accumulatedProfit;

        /* 累计推广获客链接地址 */
        @SerializedName("customers_url")
        public String customers;

        /* 赚多宝首页介绍图片 */
        @SerializedName("guide_image_url")
        public String guideImg;

        /* 赚多宝首页介绍链接地址 */
        @SerializedName("guide_link_url")
        public String guideLink;

        /* 待生效推广费地址 */
        @SerializedName("uneffective_profit_url")
        public String uneffectiveProfitUrl;

        @SerializedName("entrances")
        public List<Entrance> entrances;

        @SerializedName("activities_board_url")
        public String mActivityUrl;

        public AppAlert alert;

        @SerializedName("group_insurance")
        public GroupInsurance groupInsurance;


        public class Entrance {
            @SerializedName("icon_url")
            public String iconUrl;

            @SerializedName("title")
            public String title;

            @SerializedName("link_url")
            public String linkUrl;
        }

        public static class GroupInsurance {
            @SerializedName("link_url")
            public String linkUrl;

            @SerializedName("title")
            public String title;
        }

        public static Config create(String data) {
            if (!TextUtils.isEmpty(data)) {
                return GsonUtils.fromJson(data, Config.class);
            }
            return new Config();
        }
    }

}
